home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJSRC111.ZIP / go32 / stamp.c < prev    next >
C/C++ Source or Header  |  1993-06-26  |  1KB  |  58 lines

  1. /* This is file STAMP.C */
  2. /*
  3. ** Copyright (C) 1993 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. **
  5. ** This file is distributed under the terms listed in the document
  6. ** "copying.dj", available from DJ Delorie at the address above.
  7. ** A copy of "copying.dj" should accompany this file; if not, a copy
  8. ** should be available from where this file was obtained.  This file
  9. ** may not be distributed without a verbatim copy of "copying.dj".
  10. **
  11. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <time.h>
  17.  
  18. char key[] = "TIMETIME";
  19. char *stamp;
  20.  
  21. main(int argc, char **argv)
  22. {
  23.   FILE *f;
  24.   int key_p = 0, ch;
  25.  
  26.   long t;
  27.   time(&t);
  28.   stamp = ctime(&t);
  29.   stamp[strlen(stamp)-1] = 0;
  30.  
  31.   if (argc != 2)
  32.   {
  33.     fprintf(stderr, "Usage: stamp {program}\n");
  34.     exit(1);
  35.   }
  36.   
  37.   f = fopen(argv[1], "r+b");
  38.  
  39.   while ((ch = fgetc(f)) != EOF)
  40.   {
  41.     if (ch == key[key_p])
  42.     {
  43.       key_p++;
  44.       if (key[key_p] == 0)
  45.       {
  46.         long pos = ftell(f);
  47.         fseek(f, pos, 0);
  48.         fwrite(stamp, 1, strlen(stamp), f);
  49.         fseek(f, pos, 0);
  50.       }
  51.     }
  52.     else
  53.     key_p = 0;
  54.   }
  55.   fclose(f);
  56. }
  57.  
  58.